﻿using System;
using System.DirectoryServices;
using System.Security.Principal;

namespace zielonka.co.uk.extensions.system.directoryservices
{
    // Description:	extensions that work with SearchResult to retrieve its data.
    /*
        result.GetValue("sAMAccountName", String.Empty)
     */

    public static partial class SearchResultExtensions
    {
        public static SecurityIdentifier GetObjectSid(this SearchResult result)
        {
            if (result.Properties["objectSid"].Count > 0)
            {
                var binaryForm = (byte[])result.Properties["objectSid"][0];
                return new SecurityIdentifier(binaryForm, 0);
            }

            return null;
        }
           
    }
}
